package com.sl.au.repository;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import com.sl.au.entity.Option;

public interface OptionRepository extends JpaRepository<Option, String> {
	/**
	  * 从Option表获取分组的下拉框选项
	  * @param group
	  * @return
	  */
	 @Query("select o from Option o where o.group = ?1 order by o.createTime asc")
	 List<Option> findByGroup(String group);
	 
	 /**
	  * 从Option表通过获取分组和标题获取下拉框选项
	  * @param group
	  * @return
	  */
	 @Query("select o from Option o where o.group = ?1 and o.title = ?2 order by o.createTime asc")
	 List<Option> findByGroupAndTitle(String group, String title);
	 
	 /*
	  * Option的查找
	  */
	 @Query(" select o from Option o where o.itemOrder like '%'+?1+'%' or o.group like '%'+?1+'%' or o.title like '%'+?1+'%' order by o.group")
	 Page<Option> findOption(String key, Pageable pageable);
	 @Query(" select count(*) as num from Option o where o.itemOrder like '%'+?1+'%' or o.group like '%'+?1+'%' or o.title like '%'+?1+'%' ")
	 Long getOptionCount(String key);
}
